<template>
  <zm-index-bar class="bar" ref="indexBarRef" @scroll="handleScroll" :style="{ backgroundColor: bgc }">
    <!-- 通讯录分组上面的列表插槽 -->
    <slot name="sections"></slot>

    <view v-for="item in data" :key="item.index" @click="toPages('/pages-sub/chatCenter/userInfo')">
      <!-- 每个字母分组的索引锚点 -->
      <zm-index-anchor :index="item.index" :class="['anchor', { 'active-anchor': activeIndex === item.index }]" />
      <view v-for="(name, nameIndex) in item.data" :key="name" class="w-full h-120rpx flex items-center px-25rpx">
        <wd-img :width="'80rpx'" :height="'80rpx'" :src="headImg" round />
        <view :class="[
          'ml-31rpx',
          'flex-1',
          'h-full',
          'flex',
          'items-center',
          'border-0'
        ]">
          <view class="name">{{ name }}</view>
        </view>
      </view>
    </view>
  </zm-index-bar>
</template>

<script lang="ts" setup>
import { toPages } from '@/utils/utils';

interface Section {
  title: string;
  color: string;
  icon: string;
  clickHandler: () => void;
  messageNum?: number;
}

const props = defineProps<{
  sections: Section[];//通讯录分组上面的列表
  data: any[];
  activeIndex: string;
  bgc:'#fff';//背景颜色
  handleScroll: () => void;
}>();

const headImg = ref<string>(
  'https://qiniu.yantianzz.com/a09b4695345196d75a2de6019c4339e9.jpg',
);
</script>

<style lang="scss" scoped>
.bar {
  :deep(.wd-index-bar__sidebar) {
    .is-active {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 42rpx;
      height: 42rpx;
      color: #fff;
      background: #FF4600;
      border-radius: 21rpx 21rpx 21rpx 21rpx;
    }

    .wd-index-bar__index {
      padding: 6rpx 12rpx;
    }
  }

  .anchor {
    width: 700rpx;
    height: 46rpx;
    padding: 0 33rpx;
    margin: 31rpx auto;
    font-family: PingFang SC;
    font-size: 25rpx;
    font-style: normal;
    font-weight: 600;
    line-height: 46rpx;
    color: #30383F;
    text-align: left;
    text-transform: none;
    background: #FAFAFA;
    background-color: #fff;
    border-radius: 33rpx 33rpx 33rpx 33rpx;
  }

  .active-anchor {
    width: 700rpx;
    height: 46rpx;
    background: #FFFFFF;
    border: 2rpx solid #FFD59A;
    border-radius: 33rpx 33rpx 33rpx 33rpx;
  }

  .name {
    font-family: Roboto;
    font-size: 33rpx;
    font-style: normal;
    font-weight: 400;
    line-height: 42rpx;
    color: #30383F;
    text-align: left;
    text-transform: none;
  }

  .top_item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80rpx;
    height: 80rpx;
    border-radius: 104rpx 104rpx 104rpx 104rpx;
  }

  .messageNum {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 33rpx;
    height: 33rpx;
    font-family: Roboto;
    font-size: 21rpx;
    font-style: normal;
    font-weight: 400;
    line-height: 25rpx;
    color: #FFFFFF;
    text-align: center;
    text-transform: none;
    background: #FF3300;
    border-radius: 21rpx 21rpx 21rpx 21rpx;
  }
}
</style>
